using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Zhaoxi.MSACommerce.PaymentService.Core.Entities;

namespace Zhaoxi.MSACommerce.PaymentService.Infrastructure.Data;

public class PaymentDbContext(DbContextOptions<PaymentDbContext> options):DbContext(options)
{
    public PaymentDbContext():this (new DbContextOptions<PaymentDbContext>()){}

    public DbSet<PayLog> PayLogs => Set<PayLog>();
        
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
    }
    
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        // 设计时配置 - 只有在没有配置选项时才使用
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseMySql("server=192.168.2.178;user=root;password=RootPassword123!;database=tb_payment", new MySqlServerVersion(new Version(8, 0, 0)));
        }
    }
}